///@author:create by BZY
///Date: 2024/12/2 21:18
///Description: 获取登录Token信息
class TokenModel {
  String? accessToken;
  String? clientId;
  String? refreshToken;
  String? sub;
  String? tokenType;
  String? userId;
  String? exception;
  TokenUserInfo? userInfo;
  String? username;

  TokenModel(
      {this.accessToken,
      this.clientId,
      this.refreshToken,
      this.sub,
      this.tokenType,
      this.userId,
        this.exception,
      this.userInfo,
      this.username});

  factory TokenModel.fromJson(Map<String, dynamic> json) {
    return TokenModel(
      accessToken: json['access_token'],
      clientId: json['clientId'],
      refreshToken: json['refresh_token'],
      sub: json['sub'],
      exception: json['exception'],
      tokenType: json['token_type'],
      userId: json['user_id'],
      userInfo: json['user_info'] != null
          ? TokenUserInfo.fromJson(json['user_info'])
          : null,
      username: json['username'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['access_token'] = accessToken;
    data['clientId'] = clientId;
    data['refresh_token'] = refreshToken;
    data['sub'] = sub;
    data['token_type'] = tokenType;
    data['user_id'] = userId;
    data['exception'] = exception;
    data['username'] = username;
    data['user_info'] = userInfo?.toJson();
    return data;
  }
}

class TokenUserInfo {
  bool? accountNonExpired;
  bool? accountNonLocked;
  List<String> authorities;
  bool? credentialsNonExpired;
  bool? enabled;
  String? name;
  String? username;

  TokenUserInfo(
      {this.accountNonExpired,
      this.accountNonLocked,
      required this.authorities,
      this.credentialsNonExpired,
      this.enabled,
      this.name,
      this.username});

  factory TokenUserInfo.fromJson(Map<String, dynamic> json) {
    return TokenUserInfo(
      accountNonExpired: json['accountNonExpired'],
      accountNonLocked: json['accountNonLocked'],
      authorities: json['authorities'] != null
          ? (json['authorities'] as List).map((e) => e.toString()).toList()
          : [],
      credentialsNonExpired: json['credentialsNonExpired'],
      enabled: json['enabled'],
      name: json['name'],
      username: json['username'],
    );
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['accountNonExpired'] = accountNonExpired;
    data['accountNonLocked'] = accountNonLocked;
    data['credentialsNonExpired'] = credentialsNonExpired;
    data['enabled'] = enabled;
    data['name'] = name;
    data['username'] = username;
    data['authorities'] = authorities;
    return data;
  }
}
